home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
doorskl3.arc
/
DOORANSI.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-15
|
13KB
|
425 lines
/*
* Special ANSI input functions (advanced functions; beginners take care)
* note I've included but not tested these in association with doorskel
* itself (they were lifted whole from XDB, so they do work).
* these functions will behave differently if the user doesn't have
* graphics capabilities, but they'll get by...
*/
#include "doorskel.h"
char _fastcall ansimenu2 (char tcolor,char color,char *title,
char *lineorig,char variable[10][133]) {
/* horizontal framed menu across top of screen selectable by highlighting
further menu may be pulled down from this menu. colors are ANSI
numbers (37 = white). tcolor is the title/frame color, color is the
text color of the menus, title is the text for the title in the frame,
lineorig contains options separated by spaces (use _ within options).
the variable array contains options like lineorig, one for each
pull-down menu. this interfaces to doorhelp.c in a weird but wondrous
manner :-) by setting the current topic to the first 8 chars of the
current option and calling help(). Notice that help can't be context-
sensitive if the user doesn't have graphics capability and this function
has to emulate a pull-down as a tree-structure...
for further info you're referred to the XDB source. This is an advanced
function and you should avoid it until you feel braver...
Example:
strcpy(var[0]," Help");
strcpy(var[1],"Select");
if(gooduser)strcat(var[1]," Create Remove");
if(sysopuser)strcat(var[1]," New_Index");
strcat(var[1]," Quit");
strcpy(var[2],"Key Fields Quit");
strcpy(var[3],"Field_Names Graphics List_Header Quit");
strcpy(var[4],"Record_Fields Index_Fields Stats Filters Quit");
strcpy(var[5],"List Dump Quit");
strcpy(var[6],"");
strcpy(var[7],"");
strcpy(var[8],"");
strcpy(var[9],"");
sprintf(s," Database: %s / Index: %-1.38s ",p,index_name(idx));
strcpy(ss,"Database Index Filter Configure Status Records Quit Help");
which = ansimenu2(33,36,s,ss,var);
switch((int)which) {
...
*/
register word x,y;
char nump,numpp;
char *p[10],*pp[10];
static char *line = NULL,s[144];
char helpstring[24];
word pos[10],ppos[10],pdown,start,temp1,temp2;
char *t,was,is,temp;
/* Initially display top bar */
ReStart:
if(graphics) cls();
else printm("\n");
if(line)free(line);
line = strdup(lineorig);
if(!graphics) {
printfm("\n%s\n",title);
}
else {
printfm("\x1b[1;1H\x1b[K\x1b[0;1;%hum╔",color);
for(x=1;x<((79-strlen(title))/2);x++) printm("═");
printfm("\x1b[0;1;%hum%s\x1b[0;1;%hum",tcolor,title,color);
curr_cursor(&temp1,&temp2);
y = temp1;
for(x = y;x<79;x++) printm("═");
printm("╗\n");
curr_cursor(&temp1,&start);
}
stripcr(line);
if (!*line) return 0;
x=0;
p[x++]=strtok(line," ");
while (x<10 && (p[x++]=strtok(0," ")));
p[--x]=NULL;
if (!*p) return 0;
nump=(char)x-1;
for (x=0;p[x];x++) while (t=strchr(p[x],'_')) *t=' ';
Over: /* Redisplay top bar */
is=was=0;
for (x=0;x<9;x++) pos[x]=0;
if(graphics) {
printfm("\x1b[0;1;%hum",color);
if(baud)while (!fossil(TRANSMIT,'\r')) carrchk();
fputs("\r",stdout);
printm("\x1b[2;1H\x1b[K║ ");
}
*pos=3;
if(!graphics) {
for (x = 0;p[x];x++) {
curr_cursor(&temp1,&temp2);
if((temp1 + strlen(p[x]) + 2 + 2) > 77) printm("\n");
printfm("[%c]%s ",*p[x],&p[x][1]);
}
printm("\b\b: ");
}
else {
printm(*p);
for (x=1;p[x];x++) {
printm(" ");
printm(p[x]);
pos[x]=pos[x-1]+strlen(p[x-1])+2;
}
printm("\x1b[2;79H║\x1b[3;1H\x1b[K╚");
for(x=1;x<78;x++) printm("═");
printm("╝\x1b[2;1H");
}
Next: /* Move highlight bar */
if(graphics) {
if(baud)while (!fossil(TRANSMIT,'\r')) carrchk();
fputs("\r",stdout);
printfm("\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[was],p[was]);
printfm("\x1b[%u;1H\x1b[7m\x1b[%uC%s\x1b[0;1;%hum",start,pos[is],p[is],color);
}
was = is;
None: /* Wait for something to happen w/ top bar... */
if(!graphics) {
temp=*genin(1,0,1,1,ALLL);
if(temp=='?') {
strcpy(helpstring,"MAINHELP");
set_help(helpstring);
help();
goto ReStart;
}
if(temp)goto Direct;
else goto None;
}
temp=*genin(1,0,0,0,ARROWS);
switch ((int)temp) {
case '?':sprintf(helpstring,"%-8u",((is+1)*10));
set_help(helpstring);
printg("\x1b[15;1H\x1b[K");
help();
goto ReStart;
case 0:
case DN:
case '2': goto GotOne;
case UP:
case LEFT:
case '8':
case '4': if (is) is--;
else is = nump;
break;
case RIGHT:
case '6': if (!p[is + 1]) is = 0;
else is++;
break;
case 11:
case 27: cls();
*s = 0;
return 0;
default:
Direct:
for(x=0;p[x];x++) { /* Direct select */
if(toupper(*p[x])==toupper(temp)) {
if(is!=(char)x) {
if(graphics) {
printfm("\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[is],p[is]);
printfm("\x1b[%u;1H\x1b[7m\x1b[%uC%s\x1b[0;1;%hum",start,pos[x],p[x],color);
}
}
is=(char)x;
goto GotOne;
}
}
if(!graphics) printm("\b \b");
break;
}
goto Next;
GotOne: /* Pull down actions */
if(!graphics)printm("\n");
if(!*variable[is]) { /* No pull downs for this one */
printg("\x1b[5;1H");
return ((is+1)*10);
}
pdown=pos[is];
if(pdown>60) pdown=60;
if(graphics)printfm("\x1b[3;%uH╦\x1b[14C╦\x1b[0m\x1b[0;1;%hum\n",pdown-1,color);
for(x=0;x<9;x++)ppos[x]=0;
x=0;
strcpy(s,variable[is]);
pp[x++]=strtok(s," ");
while (x<10 && (pp[x++]=strtok(0," ")));
pp[--x]=NULL;
if (!*pp) return 0;
numpp=(char)x-1;
for (x=0;pp[x];x++) while (t=strchr(pp[x],'_')) *t=' ';;
if(!graphics) {
for (x = 0;pp[x];x++) {
curr_cursor(&temp1,&temp2);
if((temp1 + strlen(pp[x]) + 2 + 2) > 77) printm("\n");
printfm("[%c]%s ",*pp[x],&pp[x][1]);
}
printm("\b\b: ");
}
else {
for(x = 0;pp[x];x++) {
curr_cursor(&temp1,&ppos[x]);
printfm("\x1b[K\x1b[%u;%uH║ %-12.12s ║\n",ppos[x],pdown - 1,pp[x]);
}
printfm("\x1b[%u;%uH\x1b[K╚══════════════╝",ppos[numpp]+1,pdown-1);
}
was=y=0;
Over1: /* Loop until something happens */
if(graphics) {
printfm("\x1b[%u;%uH\x1b[7m %-12.12s \x1b[0;1;%hum",ppos[y],pdown,pp[y],color);
temp=*genin(1,0,0,0,ARROWS);
}
else {
temp=*genin(1,0,1,1,ALLL);
if(temp=='?') {
sprintf(helpstring,"%-8u",((is+1)*10));
set_help(helpstring);
help();
goto ReStart;
}
if(temp) goto Direct2;
else goto Over1;
}
switch ((int)temp) {
case '?':sprintf(helpstring,"%-8u",((is+1)*10)+(y+1));
set_help(helpstring);
printg("\x1b[15;1H\x1b[K");
help();
goto ReStart;
case LEFT:
case RIGHT:
case '4':
case '6': was=is;
for(x=0;pp[x];x++) {
printfm("\x1b[%u;1H\x1b[K\n",ppos[x]);
}
printfm("\x1b[%u;1H\x1b[K\n",ppos[numpp]+1);
printfm("\x1b[3;%uH═\x1b[14C═",pdown-1);
if (temp==1 || temp=='4') {
if (is) is--;
else is=nump;
}
else {
if (!p[is+1]) is=0;
else is++;
}
printfm("\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[was],p[was]);
goto Next;
case 0:
KeyPress1:
printg("\x1b[15;1H");
return (((is+1)*10)+(y+1));
case UP:
case '8': printfm("\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
if (y) y--;
else y=numpp;
break;
case DN:
case '2': printfm("\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
if (!pp[y+1]) y=0;
else y++;
break;
case 11:
case 27: for(x=0;pp[x];x++) {
printfm("\x1b[%u;1H\x1b[K\n",ppos[x]);
}
printfm("\x1b[%u;1H\x1b[K\n",ppos[numpp]+1);
*s=0;
printfm("\x1b[1;1H\x1b[K\x1b[0;1;%hum╔",color);
for(x=1;x<((79-strlen(title))/2);x++) printm("═");
printfm("\x1b[0;1;%hum%s\x1b[0;1;%hum",tcolor,title,color);
curr_cursor(&temp1,&temp2);
temp = (char)temp1;
for(x = temp;x < 79;x++) printm("═");
printm("╗\n");
goto Over;
default:
Direct2:
for(x=0;pp[x];x++) { /* Direct select */
if(toupper(*pp[x])==toupper(temp)) {
if(y!=x) {
if(graphics)printfm("\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
if(graphics)printfm("\x1b[%u;%uH\x1b[7m %-12.12s \x1b[0;1;%hum",ppos[x],pdown,pp[x],color);
}
y=x;
goto KeyPress1;
}
}
if(!graphics)printm("\b \b");
}
goto Over1;
}
char _fastcall ansimenu (char color, char *lineorig) {
/* one-line horizontal menu with options selectable by highlighting
lineorig contains options separated by spaces (use _ within
options). color is an ANSI number (37 = white). example:
option = ansimenu(32,"Quit Continue");
This interfaces to doorhelp.c by setting the current topic to
the first 8 chars of the option and calling help().
Returns the first character of the option selected, or 0 if
aborted by the user. Note that help can't be context-sensitive
if the user doesn't have graphics capabilities.
*/
register word x = 0;
static char *line = NULL;
char *p[36];
word pos[36],temp1,temp2;
char helpstring[24],*t,was,is,nump,temp;
ReStart:
if(line)free(line);
line=strdup(lineorig);
stripcr(line);
if (!strlen(line)) return 0;
p[x++]=strtok(line," ");
while (x<34 && (p[x++]=strtok(0," ")));
p[--x]=NULL;
if (!*p) return 0;
nump=(char)x-1;
for (x=0;p[x];x++) while (t=strchr(p[x],'_')) *t=' ';;
printm("\n");
if (!graphics) goto NoGraph;
Over:
is=was=0;
for (x=0;x<35;x++) pos[x]=0;
printfm("\x1b[0;1;%hum",color);
if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
fputs("\r",stdout);
*pos=1;
printm("\x1b[1C");
printm(*p);
for (x=1;p[x];x++) {
printm(" ");
printm(p[x]);
pos[x]=pos[x-1]+strlen(p[x-1])+2;
}
Next:
if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
fputs("\r",stdout);
printfm("\x1b[0;1;%hum\x1b[%uC",color,pos[was]);
printm(p[was]);
if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
fputs("\r",stdout);
printfm("\x1b[7m\x1b[%uC",pos[is]);
printm(p[is]);
printfm("\x1b[0;1;%hum",color);
was = is;
None:
temp = *genin(1,0,0,0,ARROWS);
switch((int)temp) {
case '?': sprintf(helpstring,"%-8.8s",p[is]);
set_help(helpstring);
help();
goto ReStart;
case UP:
case LEFT:
case '8':
case '4': if(is)is--;
else is=nump;
break;
case 0: return toupper(*p[is]);
case DN:
case RIGHT:
case '2':
case '6': if (!p[is+1]) is=0;
else is++;
break;
case 3: printm("\n");
goto Over;
case 11:
case 27: return 0;
default: for (x=0;p[x]!=NULL;x++) {
if (temp==*p[x]) {
return toupper(*p[x]);
}
}
break;
}
goto Next;
NoGraph:
is = was = 0;
for (x = 0;p[x];x++) {
curr_cursor(&temp1,&temp2);
if((temp1 + strlen(p[x]) + 2 + 2) > 77) printm("\n");
printfm("[%c]%s ",*p[x],&p[x][1]);
}
printm("\b\b: ");
temp = *genin(1,0,1,1,ALLL);
if(temp == '?') {
set_help("RECLINE ");
help();
goto ReStart;
}
for (x = 0;p[x];x++) {
if (temp == *p[x]) {
return toupper(*p[x]);
}
}
printm("\nInvalid choice...\n");
goto NoGraph;
}